package com.yzk.back.category.server.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yzk.back.category.server.ISysCateSer;
import com.yzk.back.model.cate.SysCategory;
import com.yzk.frame.orm.dao.GenericDAO;
import com.yzk.frame.utils.util.Page;

@Transactional(readOnly=false)
@Service
public class SysCateSerImpl implements ISysCateSer {

	private GenericDAO<SysCategory,Long> dao ;
	
	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		dao = new GenericDAO<SysCategory,Long>(entityManager,SysCategory.class);
	}
	
	
	@Override
	public void save(SysCategory entity) {
		dao.save(entity);
		System.out.println("save sucessful!!!");
	}

	@Override
	public List<SysCategory> listCate() {
		return this.dao.query("select c from SysCategory c") ;
	}

	@Transactional(readOnly=true)
	public SysCategory findById(Long id) {
		return this.dao.findById(id);
	}

	@Override
	public boolean delCate(Long id) {
		return this.dao.delete(id);
	}

	@Override
	public Page<SysCategory> getByPage(Page<SysCategory> page) {
		return this.dao.findByPage(page, "select c from SysCategory c");
	}



}
